 //
//  HHPHTTPRequestOptions.h
//  HHPHTTPRequest
//
//  Created by 韩红坡 on 2016/12/13.
//  Copyright © 2016年 韩红坡. All rights reserved.
//

#import <Foundation/Foundation.h>

#import "AFNetworking.h"

@class HHPHTTPRequest;

typedef NS_ENUM(NSUInteger, HHPHTTPMethod) {
    HHPHTTPMethodPost,
    HHPHTTPMethodGet,
};

typedef NS_ENUM(NSUInteger, HHPHTTPRequestBodyType) {
    HHPHTTPRequestBodyTypeHTTP,
    HHPHTTPRequestBodyTypeJSON,
};

typedef NS_ENUM(NSUInteger, HHPHTTPResponseBodyType) {
    HHPHTTPResponseBodyTypeHTTP,
    HHPHTTPResponseBodyTypeJSON,
};

/** 
 * 预处理返回的内容
 * 可以用来解析模型，或抛出错误
 * 返回的id类型可以为NSError*，表示解析失败
 */
@protocol HHPHTTPDataHandlerProtocol <NSObject>

- (id)handleData:(id)data task:(NSURLSessionDataTask *)task;

@end

/**
 * 预处理返回的错误
 * 可以用来修改错误提示，统一的异常处理
 */
@protocol HHPHTTPErrorHandlerProtocol <NSObject>

- (NSError *)handleError:(NSError *)error task:(NSURLSessionDataTask *)task;

@end

/**
 * 预处理加密请求
 * 可以用来加密请求参数
 */
@protocol HHPHTTPEncryptHandlerProtocol <NSObject>

- (NSMutableDictionary<NSString *, id> *)handleEncryptRequestParams:(NSMutableDictionary<NSString *, id> *)requestParams;

@end


@interface HHPHTTPRequestOptions : NSObject

/** 请求数据类型，form表单或json，只对post请求有效 */
@property (nonatomic, assign) HHPHTTPRequestBodyType requestBodyType;
/** 返回数据类型，文本或json */
@property (nonatomic, assign) HHPHTTPResponseBodyType responseBodyType;
/** 超时时间 */
@property (nonatomic, assign) NSTimeInterval timeout;
/** 可以接受的mime返回类型，如text/plain、text/json、application/json */
@property (nonatomic, strong) NSSet *acceptContentTypes;
/** 安全协议 */
@property (nonatomic, strong) AFSecurityPolicy *securityPolicy;
/** 缓存方案 */
@property (nonatomic, assign) NSURLRequestCachePolicy cachePolicy;
/** 返回数据过滤器 */
@property (nonatomic, strong) id<HHPHTTPDataHandlerProtocol> dataHandler;
/** 错误过滤器 */
@property (nonatomic, strong) id<HHPHTTPErrorHandlerProtocol> errorHandler;
/** 加密请求handler */
@property (nonatomic, strong) id<HHPHTTPEncryptHandlerProtocol> encryptHandler;
/** 默认请求头 */
@property (nonatomic, strong) NSDictionary<NSString *, NSString *> *defaultHeaders;
/** 如果发生错误，重试请求 */
@property (nonatomic, strong) BOOL (^retryBlock)(HHPHTTPRequest *request);

@end
